package exercicios.lista.ex01;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/exercicios/ex01/ex01")
public class TabuadaServlet extends HttpServlet{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException{
		imprimirTabuadaHTML(req, res);
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException{
		imprimirTabuadaHTML(req, res);
	}
	
	public void imprimirTabuadaHTML(HttpServletRequest req, HttpServletResponse res) throws IOException{
		PrintWriter out;
		int numero = Integer.parseInt(req.getParameter("numero"));
		res.setContentType("text/html");
		out = res.getWriter();
		out.println("<html><head><title>");
		out.println("Tabuada");
		out.println("</title></head><body>");
		out.println("<h3>Tabuada do n&uacute;mero "+ numero+"</h3>");
		out.println("<table border='1'>");
		for(int i = 0 ; i <= 10 ; ++i){
			out.println("<tr><td>"+numero+"</td>"+
					"<td>x</td><td>"+i+"</td><td>="+numero*i+"</td></tr>");
		}
		out.println("</table>");
		out.println("</body></html>");
		out.close(); 
	}

}
